package com.ddwl.user.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.constant.Constant;
import com.ddwl.common.dao.TkDao;
import com.ddwl.user.dao.mapper.UserAddrMapper;
import com.ddwl.user.dao.model.UserAddr;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.time.Instant;


/**
 * (SysUserAddr)表数据库访问层
 *
 * @author makejava
 * @since 2020-06-03 15:51:41
 */
@Repository
public class UserAddrDao extends TkDao<UserAddrMapper, UserAddr> {


    /**
     * 移除默认收货地址
     * @param userId
     */
    public void removeDefault(String userId) {
        Example example = new Example(UserAddr.class);
        example.and().andEqualTo("userId",userId)
        .andEqualTo("dflag", BaseEnum.DflagEnum.NOT_DELETE.getCode())
        .andEqualTo("defaultFlag",BaseEnum.StatusEnum.ENABLE.getCode());
        UserAddr sysUserAddr =  new UserAddr();
        sysUserAddr.setDefaultFlag(BaseEnum.StatusEnum.DISABLE.getCode());
        sysUserAddr.setGmtModified(Instant.now());
        updateByPrimaryKeySelective(sysUserAddr);
        baseMapper.updateByExampleSelective(sysUserAddr,example);
    }
}